﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class wDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string sqlConnString = "Data Source=asdf80730.no-ip.org;Initial Catalog=project;Persist Security Info=True;User ID=sa;Password=P@ssword";//設定資料庫名稱與路徑
        SqlConnection cnn = new SqlConnection(sqlConnString);//建立Connection 物件
        int WId = Convert.ToInt32(Request.QueryString["id"]);
        int SMId = Convert.ToInt32(Session["MId"]);

        cnn.Open();//使用Open開啟資料庫

        SqlCommand cmd = new SqlCommand("SELECT Wanted.MId FROM Wanted WHERE Wanted.WId=" + WId, cnn);
        SqlDataReader sqlreader;
        sqlreader = cmd.ExecuteReader();


        if (sqlreader.Read())
        {
            int MId = sqlreader.GetSqlInt32(0).Value;
            //Response.Write("<script language=JavaScript>alert('" + "Session[Mid]=" + SMId + ",tagetWId=" + WId + ",發布人=" + MId + "')</script>");
          
            if (MId == SMId)
                NegotiationButton.Visible = false;
            else
                NegotiationButton.Visible = true;
          
        }
        else
        {
          //  btnDeal.Visible = true;
            Response.Write("<script language=JavaScript>alert('登入失敗')</script>");
        }
        cnn.Close();
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Session["MId"] == null)//會員
            this.Page.MasterPageFile = "~/MasterPage.master";
        else       //一般使用者
            this.Page.MasterPageFile = "~/LoginedMasterPage.master";
    }
    protected void NegotiationButton_Click(object sender, EventArgs e)
    {
        /*
       DataSet dataSet = new DataSet();

       dataSet = wDetailsView.DataSource;
       */



        //物品名稱
        //String rows0 = wDetailsView.Rows[0].Cells[1].Text;
        //String WGName = wDetailsView.Rows[0].Cells[1].Text;
        Session["WGName"] = wDetailsView.Rows[0].Cells[1].Text;

        //品牌
        //String rows1 = wDetailsView.Rows[1].Cells[1].Text;
        //String WGBrand = wDetailsView.Rows[1].Cells[1].Text;
        Session["WGBrand"] = wDetailsView.Rows[1].Cells[1].Text;

        //WId
        //String rows2 = wDetailsView.Rows[2].Cells[1].Text;
        String WId = wDetailsView.Rows[2].Cells[1].Text;
        Session["WId"] = wDetailsView.Rows[2].Cells[1].Text;
        //上架日期 (暫時用不到)
        /*
        String rows3 = wDetailsView.Rows[3].Cells[1].Text;
        String WStart = wDetailsView.Rows[3].Cells[1].Text;
        Session["WStart"] = wDetailsView.Rows[3].Cells[1].Text;
        */

        //結束日期 (暫時用不到)
        /*
        String rows4 = wDetailsView.Rows[4].Cells[1].Text;
        String WEnd = wDetailsView.Rows[4].Cells[1].Text;
        Session["WEnd"] = wDetailsView.Rows[4].Cells[1].Text;
        */

        //商品配送方式
        //String rows5 = wDetailsView.Rows[5].Cells[1].Text;
        String WTran = wDetailsView.Rows[5].Cells[1].Text;
        Session["WTran"] = wDetailsView.Rows[5].Cells[1].Text;

        //WVisible
        //String rows6 = wDetailsView.Rows[6].Cells[1].Text;
        //String WVisible = wDetailsView.Rows[6].Cells[1].Text;
        Session["WVisible"] = wDetailsView.Rows[6].Cells[1].Text;
        //商品用途
        //String rows7 = wDetailsView.Rows[7].Cells[1].Text;
        //String WGApp = wDetailsView.Rows[7].Cells[1].Text;
        Session["WGApp"] = wDetailsView.Rows[7].Cells[1].Text;

        //數量
        //String rows8 = wDetailsView.Rows[8].Cells[1].Text;
        //String WGAmount = wDetailsView.Rows[8].Cells[1].Text;
        Session["WGAmount"] = wDetailsView.Rows[8].Cells[1].Text;

        //商品描述
        //String rows9 = wDetailsView.Rows[9].Cells[1].Text;
        String WGDescription = wDetailsView.Rows[9].Cells[1].Text;
        Session["WGDescription"] = wDetailsView.Rows[9].Cells[1].Text;

        //製造年份
        //String rows10 = wDetailsView.Rows[10].Cells[1].Text;
        //String WGYear = wDetailsView.Rows[10].Cells[1].Text;
        Session["WGYear"] = wDetailsView.Rows[10].Cells[1].Text;

        //產地
        //String rows11 = wDetailsView.Rows[11].Cells[1].Text;
        //String WGMadeIn = wDetailsView.Rows[11].Cells[1].Text;
        Session["WGMadeIn"] = wDetailsView.Rows[11].Cells[1].Text;
        //預算
        //String rows12 = wDetailsView.Rows[12].Cells[1].Text;
        //String WGBudget = wDetailsView.Rows[12].Cells[1].Text;
        Session["WGBudget"] = wDetailsView.Rows[12].Cells[1].Text;

        //備註
        //String rows13 = wDetailsView.Rows[13].Cells[1].Text;
        //String WNote = wDetailsView.Rows[13].Cells[1].Text;
        Session["WNote"] = wDetailsView.Rows[13].Cells[1].Text;

        //WGPId
        //String rows14 = wDetailsView.Rows[14].Cells[1].Text;
        //String WGPId = wDetailsView.Rows[14].Cells[1].Text;
        Session["WGPId"] = wDetailsView.Rows[14].Cells[1].Text;
        //商品種類
        //String rows15 = wDetailsView.Rows[15].Cells[1].Text;
        //String GCthird = wDetailsView.Rows[15].Cells[1].Text;
        Session["GCthird"] = wDetailsView.Rows[15].Cells[1].Text;

        //交易狀態
        //String rows16 = wDetailsView.Rows[16].Cells[1].Text;
        //String HCName = wDetailsView.Rows[16].Cells[1].Text;
        Session["HCName"] = wDetailsView.Rows[16].Cells[1].Text;

        //通緝圖片 (暫時不用)
        //String rows17 = wDetailsView.Rows[17].Cells[1].Text;
        //String GPServName = wDetailsView.Rows[17].Cells[1].Text;
        Session["GPServName"] = wDetailsView.Rows[17].Cells[1].Text;


        Response.Redirect("negotiation.aspx");


        /*
        Response.Redirect("negotiation.aspx?WGName='" + WGName + "'&WGBrand='" + WGBrand
            + "'&WId='" + WId + "'&WTran='" + WTran + "'&WVisible='" + WVisible + "'&WGApp='" + WGApp
            + "'&WGDescription='" + WGDescription + "'&WGYear='" + WGYear + "'&WGMadeIn='" + WGMadeIn
            + "'&WGBudget='" + WGBudget + "'&WNote='" + WNote + "'&WGPId='" + WGPId + "'&GCthird='" + GCthird
            + "'&HCName='" + HCName + "'&GPServName='" + GPServName);
        */

        /*
        Response.Write(rows0 + "," + rows1 + "," + rows2 + "," + rows3 + "," + rows4 + "," + rows5 + "," + rows6 + "," + rows7 + "," + rows8
        + "," + rows9 + "," + rows10 + "," + rows11 + "," + rows12 + "," + rows13 + "," + rows14 + "," + rows15 + "," + rows16 + "," + rows17);
        */

    }
}